package tedu.week04.day02_thread.lesson4;

/**
 * <pre>
 *      生产者与消费者-信息类.
 *
 * </pre>
 *
 * @author : resty
 * @date : 2019年07月09日    14时
 **/
public class Info {
    private String title;
    private String content;
    //getter/setter方法略
    boolean flag = true;
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public synchronized void set(String title, String content) {
        if (!flag){
            try {
                super.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        setTitle(title);
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        setContent(content);

        flag= false;
        notify();
    }
    public synchronized void get(){
        if(flag){
            try {
                super.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getTitle()+getContent());
        flag = true;
        notify();
    }
}
